home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWToolbx / Sources / SLMacOS.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  6.5 KB  |  227 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLMacOS.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifdef FW_BUILD_MAC
  13.  
  14. #ifndef SLMACOS_H
  15. #include "SLMacOS.h"
  16. #endif
  17.  
  18. #ifndef FWPRIDEB_H
  19. #include "FWPriDeb.h"
  20. #endif
  21.  
  22. #ifndef FWSOMENV_H
  23. #include "FWSOMEnv.h"
  24. #endif
  25.  
  26. #ifndef FWRECT_H
  27. #include "FWRect.h"
  28. #endif
  29.  
  30. #ifndef FWCFMRES_H
  31. #include "FWCFMRes.h"
  32. #endif
  33.  
  34. #if defined(FW_BUILD_MAC) & !defined(__RESOURCES__)
  35. #include <Resources.h>
  36. #endif
  37.  
  38. //========================================================================================
  39. //    Runtime Informations
  40. //========================================================================================
  41.  
  42. #ifdef FW_BUILD_MAC    
  43. #pragma segment fwtoolbx
  44. #endif
  45.  
  46. //========================================================================================
  47. //    Mac OS Utlities
  48. //========================================================================================
  49.  
  50. //----------------------------------------------------------------------------------------
  51. //    FW_PrivMacBuildWindowRegions
  52. //----------------------------------------------------------------------------------------
  53. //    Calculate window size including structure region (i.e. title bar). To do this we need,
  54. //    if the window isn't shown, to force the window to compute its structure region by
  55. //    calling its defproc. If build is false, set the regions back to empty regions, so
  56. //    as not to confuse the window manager. Return the previous state of the regions.
  57.  
  58. typedef pascal long(*WDefProcType)(short varCode,
  59.                                    WindowPtr theWindow,
  60.                                    short message,
  61.                                    long param);
  62.  
  63. typedef WDefProcType *WDefProcTypeHandle;
  64.  
  65. static Handle MacGetAndLoadWDefProc(Handle windowDefProc)
  66. {
  67.     if ((*windowDefProc))                        // if Master Ptr is NULL => resource is purged
  68.         return windowDefProc;
  69.     else
  70.     {
  71.         FW_SOMEnvironment ev;
  72.         FW_CAcquireCFMResourceAccess qr(ev);
  73.         ::LoadResource(windowDefProc);
  74.         if (::ResError() == noErr)                // only return it if the LoadResource worked
  75.             return windowDefProc;
  76.         else
  77.             return NULL;
  78.     }
  79. }
  80.  
  81. FW_Boolean FW_PrivMacBuildWindowRegions(WindowPtr windowPtr, FW_Boolean build, FW_PlatformError* error)
  82. {
  83.     FW_ERR_TRY
  84.     {
  85.         FW_ASSERT(windowPtr != NULL);
  86.     
  87.         WindowRecord &theWindowRecord = *((WindowPeek)windowPtr);
  88.     
  89.         // The regions are considered to be built if either:
  90.         //  a) the window is shown; or
  91.         //  b) the structure rgn is not empty.
  92.     
  93.         if (theWindowRecord.visible || !::EmptyRgn(theWindowRecord.strucRgn))
  94.         {
  95.             if ((build != true) && !theWindowRecord.visible)
  96.             {
  97.                 ::SetEmptyRgn(theWindowRecord.strucRgn);
  98.                 ::SetEmptyRgn(theWindowRecord.contRgn);
  99.             }
  100.             return true;
  101.         }
  102.         else
  103.         {
  104.             if (build == true)
  105.             {
  106.                 WDefProcTypeHandle wDefProc = (WDefProcTypeHandle)MacGetAndLoadWDefProc(theWindowRecord.windowDefProc);
  107.                 if (wDefProc)
  108.                 {
  109.                     SignedByte savedState = ::HGetState((Handle)wDefProc);
  110.                     ::HLock((Handle)wDefProc);
  111.     //                WindowDefUPP windowDefUPP = NewWindowDefProc(*wDefProc);
  112.                     WindowDefUPP windowDefUPP = (WindowDefUPP) NewRoutineDescriptor((ProcPtr)(*wDefProc), uppWindowDefProcInfo, ((ISAType) kM68kISA));
  113.                     if (windowDefUPP == NULL)
  114.                         *error = FW_xMemoryExhausted;
  115.                     else
  116.                     {
  117.                         CallUniversalProc(windowDefUPP, uppWindowDefProcInfo, ::GetWVariant(windowPtr), windowPtr, wCalcRgns, 0);
  118.                         DisposeRoutineDescriptor(windowDefUPP);
  119.                         ::HSetState((Handle)wDefProc, savedState);
  120.                     }
  121.                 }
  122.             }
  123.             return false;
  124.         }
  125.     }
  126.     FW_ERR_CATCH
  127.     
  128.     return false;
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // FW_MacGetMaxIntersectedDevice
  133. //----------------------------------------------------------------------------------------
  134.  
  135. GDHandle  FW_MacGetMaxIntersectedDevice(WindowPtr windowPtr, FW_SRect& screenRect, FW_PlatformError* error)
  136. {
  137.     GDHandle maxSectGD = NULL;
  138.  
  139.     FW_ERR_TRY
  140.     {
  141.         FW_ASSERT(windowPtr != NULL);
  142.         
  143.         FW_Boolean rgnsWereBuilt = FW_PrivMacBuildWindowRegions(windowPtr, true, error);
  144.         if (*error)
  145.             return NULL;
  146.     
  147.         Rect globalStrucRect = (*(((WindowPeek)windowPtr)->strucRgn))->rgnBBox;
  148.         FW_PrivMacBuildWindowRegions(windowPtr, rgnsWereBuilt, error);
  149.         if (*error)
  150.             return NULL;
  151.         
  152.         long maxSectArea = 0;
  153.         Rect moveBounds = (*(GetGrayRgn()))->rgnBBox;
  154.         InsetRect(&moveBounds, 4, 4);
  155.     
  156.         GDHandle aGDHandle = ::GetDeviceList();
  157.         maxSectGD = ::GetMainDevice();    // Set as best choice default 
  158.         while (aGDHandle)
  159.         {                                        // calc which scrn intersects largest part of window
  160.             if (::TestDeviceAttribute(aGDHandle, screenDevice) && ::TestDeviceAttribute(aGDHandle, screenActive))
  161.             {
  162.                 Rect aGDScreenRect = (*aGDHandle)->gdRect;
  163.                 Rect gdSectRect;
  164.                 Rect dontCare;
  165.                 if (::SectRect(&aGDScreenRect, &moveBounds, &dontCare) && ::SectRect(&globalStrucRect, &aGDScreenRect, &gdSectRect))
  166.                 {
  167.                     long sectArea = (gdSectRect.bottom - gdSectRect.top) * (gdSectRect.right - gdSectRect.left);
  168.                     if (sectArea > maxSectArea)    // do we have a new winner? 
  169.                     {
  170.                         maxSectArea = sectArea;
  171.                         maxSectGD = aGDHandle;
  172.                     }
  173.                 }
  174.             }
  175.             aGDHandle = ::GetNextDevice(aGDHandle);
  176.         }
  177.     
  178.         FW_CRect* castedRect = (FW_CRect*)&screenRect;
  179.         
  180.         if (maxSectGD != ::GetMainDevice())
  181.             *castedRect = (*maxSectGD)->gdRect;
  182.         else
  183.         {
  184.             // Account for menu bar on the main screen.
  185.             // Don't just assume that its at the top of
  186.             // the screen!
  187.             Rect gdRect = (*maxSectGD)->gdRect;
  188.     
  189.             RgnHandle tempRgn = ::NewRgn();
  190.             if (tempRgn == NULL)
  191.             {
  192.                 *error = FW_xMemoryExhausted;
  193.                 return NULL;
  194.             }
  195.             ::RectRgn(tempRgn, &gdRect);                // main screen with menubar 
  196.             ::SectRgn(tempRgn, GetGrayRgn(), tempRgn);    // GetGrayRgn == desktop rgn w/o menubar 
  197.             *castedRect = (*tempRgn)->rgnBBox;            // => main screen w/o menubar 
  198.             ::DisposeRgn(tempRgn);
  199.         }
  200.     }
  201.     FW_ERR_CATCH
  202.  
  203.     return maxSectGD;
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //  FW_MacZoomWindow: 
  208. //----------------------------------------------------------------------------------------
  209.  
  210. FW_PlatformError FW_MacZoomWindow(WindowPtr windowPtr, FW_Boolean zoomIn)
  211. {
  212.     // No try block necessary - Do not throw
  213.     GrafPtr curGrafPort;
  214.     ::GetPort(&curGrafPort);
  215.     ::SetPort(windowPtr);                                // The ROM requires that thePort be the window being zoomed.
  216.  
  217.     ::ClipRect(&windowPtr->portRect);
  218.     ::EraseRect(&windowPtr->portRect);
  219.     ::ZoomWindow(windowPtr, zoomIn ? inZoomIn : inZoomOut, true);
  220.  
  221.     ::SetPort(curGrafPort);
  222.     
  223.     return FW_xNoError;
  224. }
  225.  
  226. #endif
  227.